using System;
using System.Collections.Generic;
using UnityEngine;

namespace HYOK
{
    /// <summary>
    /// UI资源路径获取工具类
    /// </summary>
    public class UIResPathAssistant
    {

#if UNITY_EDITOR || UNITY_STANDALONE_WIN
        //资源路径，程序开发时候用，正式环境不走这里
        private static Dictionary<long, NPCommonAssetPathInfo> _m_uiPathDict = new Dictionary<long, NPCommonAssetPathInfo>()
        {
            #region Common
            {UIResPathConst.WIN_TOOL_TIP_TEXT, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_tool_tip_text_vertical")},
            {UIResPathConst.WIN_TOOL_TIP_TEXT_FOLLOW, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_tool_tip_text_horizontal")},

            {UIResPathConst.WIN_TOOL_TIP_ICON_DETAIL, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_tool_tip_icon_detail")},
            {UIResPathConst.WIN_COMMON_RESOURCES_TIP, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_resources_tip")},
            {UIResPathConst.WIN_GET_ITEM, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_get_item")},
            {UIResPathConst.WIN_COMMON_RESOURCES_WITHOUTBAG_TIP, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_resources_withoutbag_tip")},
            {UIResPathConst.WIN_MUSEUM_FARGMENT_AUTO_COMPOSE, new NPCommonAssetPathInfo("gui/museum.unity3d", "win_museum_fargment_auto_compose")},
            {UIResPathConst.WIN_COMMON_COST_TOGGLE_DIALOG, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_cost_toggle_dialog")},
            {UIResPathConst.WIN_COMMON_TOGGLE_DIALOG, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_toggle_dialog")},
            {UIResPathConst.WIN_COMMON_ACCESS_WAYS, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_access_ways")},
            {UIResPathConst.WIN_COMMON_PLAYER_BUSINESS_CARD_TIP, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_player_business_card_tip")},
            {UIResPathConst.WIN_LOADING_MIST, new NPCommonAssetPathInfo("gui/common_ui.unity3d", "win_loading_mist")},
            {UIResPathConst.WIN_COMMON_BACK, new NPCommonAssetPathInfo("gui/common_gui.unity3d", "win_common_back")},
            {UIResPathConst.WIN_BURST_PARTICLE, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_burst_particle")},
            {UIResPathConst.WIN_CENTER_TIPS, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "center_tips")},
            {UIResPathConst.WIN_COMMON_TOGGLE_FORCE_DIALOG, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_toggle_force_dialog")},
            {UIResPathConst.WIN_COMMON_COST_DIALOG, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_cost_dialog")},
            {UIResPathConst.WIN_COMMON_REWARD_PREVIEW, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_reward_preview")},
            {UIResPathConst.WIN_COMMON_RENAME,new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_rename")},

            {UIResPathConst.C_FLOURISH_TIP_RES_ID, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "player_flourish_tips")},

            {UIResPathConst.C_DEFAULT_RESBAR_RES_ID, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_resbar_1")},
            
            {UIResPathConst.WIN_COMMON_SHARE_MAIN, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_share")},
            {UIResPathConst.PREFAB_COMMON_SHARE_FRIEND_PAGR, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "prefab_common_share_friend_page")},

            {UIResPathConst.WIN_GET_SPECIAL_ITEM, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_get_showoffitem")},
            {UIResPathConst.WIN_COMMON_SKIP, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_common_skip")},
            {UIResPathConst.WIN_SCREEN_SFX, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "win_screen_sfx")},

            {UIResPathConst.WIN_TUTORIAL_MOVE_MASK, new NPCommonAssetPathInfo("gui/tutorial_gui.unity3d", "guide_movementmask")},
                
            {UIResPathConst.PREFAB_COMMON_ACCESS_WAYS_COMBINED_ITEM, new NPCommonAssetPathInfo("gui/game_gui.unity3d", "prefab_common_access_ways_item3")},
            
            #endregion
            #region 登录 2300-2399
            
            {2301, new NPCommonAssetPathInfo("gui/login_gui.unity3d", "win_login_game")},
            {2302, new NPCommonAssetPathInfo("gui/login_gui.unity3d", "win_login_choose_server")},
            {2304, new NPCommonAssetPathInfo("gui/login_gui.unity3d", "win_login_account_way")},
            {2306, new NPCommonAssetPathInfo("gui/login_gui.unity3d", "win_use_account")},
            {2307, new NPCommonAssetPathInfo("gui/login_gui.unity3d", "account_grid")},
            {2310, new NPCommonAssetPathInfo("gui/login_gui.unity3d", "wnd_queue")},

            #endregion

        };
#endif

        /// <summary>
        /// 获取assetPath
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        public static NPCommonAssetPathInfo getAssetInfo(long _id)
        {
#if NP_GAME
            NPUIResPathRefObj uiResPathRefObj = GRefdataCoreMgr.instance.uiResPathRefCore.getRef(_id);
            if (null == uiResPathRefObj)
            {

#if UNITY_EDITOR || UNITY_STANDALONE_WIN
                NPCommonAssetPathInfo commonAssetPathInfo = null;
                if (_m_uiPathDict.TryGetValue(_id, out commonAssetPathInfo))
                {
                    return commonAssetPathInfo;
                }
#endif
                Debug.LogError($"ui_res_path配置缺失，Id:{_id}");
                return null;
            }
            else
            {
                return uiResPathRefObj;
            }
#else
            return null;
#endif
        }

        /// <summary>
        /// 获取assetPath
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        public static string getAssetPath(long _id)
        {
#if NP_GAME
            NPUIResPathRefObj uiResPathRefObj = GRefdataCoreMgr.instance.uiResPathRefCore.getRef(_id);
            if (null == uiResPathRefObj)
            {

#if UNITY_EDITOR || UNITY_STANDALONE_WIN
                NPCommonAssetPathInfo commonAssetPathInfo = null;
                if (_m_uiPathDict.TryGetValue(_id, out commonAssetPathInfo))
                {
                    return commonAssetPathInfo.asset_path;
                }
#endif

                Debug.LogError($"ui_res_path配置缺失，Id:{_id}");
                return String.Empty;
            }
            else
            {
                return uiResPathRefObj.asset_path;
            }
#else
            return String.Empty;
#endif
        }

        /// <summary>
        /// 获取objName
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        public static string getObjName(long _id)
        {
#if NP_GAME
            NPUIResPathRefObj uiResPathRefObj = GRefdataCoreMgr.instance.uiResPathRefCore.getRef(_id);
            if (null == uiResPathRefObj)
            {

#if UNITY_EDITOR || UNITY_STANDALONE_WIN
                NPCommonAssetPathInfo commonAssetPathInfo = null;
                if (_m_uiPathDict.TryGetValue(_id, out commonAssetPathInfo))
                {
                    return commonAssetPathInfo.obj_name;
                }
#endif
                Debug.LogError($"ui_res_path配置缺失，Id:{_id}");
                return String.Empty;
            }
            else
            {
                return uiResPathRefObj.obj_name;
            }
#else
           return String.Empty;
#endif
        }

        /// <summary>
        /// 校验资源，判断程序定义的跟策划配置的是否对的上
        /// </summary>
        public static void CheckRes()
        {
#if NP_GAME
#if UNITY_EDITOR
            foreach (long id in _m_uiPathDict.Keys)
            {
                NPUIResPathRefObj npuiResPathRefObj = GRefdataCoreMgr.instance.uiResPathRefCore.getRef(id);
                if (null == npuiResPathRefObj)
                {
                    NPCommonAssetPathInfo commonAssetPathInfo = null;
                    if (_m_uiPathDict.TryGetValue(id, out commonAssetPathInfo))
                    {
                        Debug.LogError($"ui_res_path配置缺失，Id:{id};路径:{commonAssetPathInfo.ToString()}");
                    }
                    else
                    {
                        Debug.LogError($"ui_res_path配置缺失，Id:{id}");
                    }
                }
            }
#endif
#endif
        }
    }
}